using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace LAFDC.DataAccess
{
    public class ConnectionManager
    {
        private string ConnectionString = "Data Source=localhost;Initial Catalog=LAFDC;Integrated Security=SSPI;";

        public ConnectionManager()
        {
            // Constructor
        }

        public SqlConnection GetSqlConnection()
        {
            
            SqlConnection conn = new SqlConnection(ConnectionString);
            return conn;
        }

        public string GetConnectionString()
        {
            return this.ConnectionString;
        }

    }

    public class QueryGenerator
    {

    }
}

namespace LAFDC.Web.UI
{
    public class FormChangeTracker
    {
        public static List<string> mChangedObjects = new List<string>();
        public static List<string> mChangedContact = new List<string>();
        public static List<string> mChangedFamille = new List<string>();

        public void RegisterChange(string tableName)
        {
            if ( ! mChangedObjects.Contains(tableName))
            {
                mChangedObjects.Add(tableName);
            }
        }
        public void RegisterContactChange(string contactId)
        {
            if (!mChangedContact.Contains(contactId))
            {
                mChangedContact.Add(contactId);
            }
        }

        public void RegisterFamilleChange(string changeFamille)
        {
            if (!mChangedFamille.Contains(changeFamille))
            {
                mChangedFamille.Add(changeFamille);
            }
        }
    }
}

namespace LAFDC.Logging
{
    public static class FDCLogger
    {
        private static int iLoggingLevel;
        public static int LoggingLevel
        {
            set
            {
                if (LoggingLevel < 4)
                {
                    iLoggingLevel = value;
                }
                else
                {
                    iLoggingLevel = 4;
                }
            }
            get { return iLoggingLevel; }
        }

        public static void LogEvent(string description, string Module, int severity)
        {
            LoggingLevel = 4;

            DateTime dt = DateTime.Now;

            string LogEntry = "EventTime='" + dt.ToString() + "', Severity='"
                + severity.ToString() + "', Module='" + Module
                + "', Description='" + description + "'";

            if (severity <= iLoggingLevel)
            {
                    LogEvent(LogEntry);
            }
        }	


        private static void LogEvent(string LogEntry)
        {
            string logFile = "LAFDCWeb.log";
            string logDir = "C:\\program files\\LAFDC\\LAFDCWeb\\Logging";
            string logPath = logDir + "\\" + logFile;

            try
            {
                if (!Directory.Exists(logDir))
                {
                    Directory.CreateDirectory(logDir);
                }

                // Check if the file exist before trying to write events there;
                if (!File.Exists(logPath))
                {
                    using (StreamWriter sw = new StreamWriter(logPath))
                    {
                        sw.Close();
                    }
                }

                using (StreamWriter sw = new StreamWriter(logPath, true))
                {
                    sw.WriteLine(LogEntry);
                    sw.Close();
                }
            }
            catch
            {
            }

        }


    }
}